package com.tuozixuan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tuozixuan.entity.User;
import com.tuozixuan.service.UserService;

@RestController
@RequestMapping("/test")
public class TestController {

	@Autowired
	private UserService userService;

	@GetMapping("/getUserById")
	public User getUserById(@RequestParam("id") String id) {
		User user = userService.getUserById(Long.valueOf(id));
		return user;
	}
	
	@GetMapping("/findAll")
	public List<User> findAll() {
		List<User> userList = userService.listUser();
		return userList;
	}

	@GetMapping("/saveUser")
	public String saveUser() {
		User user = new User();
		user.setName("test");
		user.setAge(3);
		user.setAddress("address");
		userService.save(user);
		return "ok";
	}
}
